package com.drojian;

import com.drojian.pojo.AndroidRoot;
import com.google.gson.Gson;

import org.junit.Test;

import java.io.IOException;

import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class WanAndroidTest {
    Retrofit retrofit = new Retrofit.Builder().baseUrl("https://www.wanandroid.com/").build();
    WanAndroid service = retrofit.create(WanAndroid.class);

    @Test
    public void test1() throws IOException {
        Call<ResponseBody> call = service.login("清河集一枝花", "xujiaqi2002.");
        Response<ResponseBody> response = call.execute();
        String string = response.body().string();
        System.out.println(string);
        AndroidRoot root = new Gson().fromJson(string, AndroidRoot.class);
        System.out.println(root.toString());
        System.out.println(root.getData().toString());
    }

    /**
     * @throws IOException
     * 加入转换器后的
     */
    Retrofit retrofit1 = new Retrofit
            .Builder()
            .baseUrl("https://www.wanandroid.com/")
            .addConverterFactory(GsonConverterFactory.create())
            .build();
    WanAndroid2 service1 = retrofit1.create(WanAndroid2.class);

    @Test
    public void loginConvertTest() throws IOException {
        Call<AndroidRoot> call = service1.login("清河集一枝花", "xujiaqi2002.");
        Response<AndroidRoot> execute = call.execute();
        AndroidRoot body = execute.body();
        System.out.println(body.toString());
    }
    /**
     * 加入适配器
     */
}
